/**
 * 
 */
package design_pattern.flyweight.composite;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author linzq
 * 
 */
public class ConcreteCompositeFlyweight implements Flyweight {

  private HashMap<Character, Flyweight> files = new HashMap<>();

  private Flyweight flyweight;

  public ConcreteCompositeFlyweight() {}

  public void add(Character key, Flyweight flyweight) {
    files.put(key, flyweight);
  }

  @Override
  public void operation(String state) {
    Flyweight fly = null;
    for (Iterator it = files.entrySet().iterator(); it.hasNext();) {
      Map.Entry<Character, Flyweight> entry = (Map.Entry<Character, Flyweight>) it.next();
      fly = entry.getValue();
      fly.operation(state);
    }
  }

}
